OOFGraph is a class library which allows you to display data contained within an oofile database as a graph or chart. With only a few lines of code, you can create clear and concise graphical representations of your data.
What do I need to create a graph?
First you'll need an OOFILE database. You can find out how to create an OOFILE database by reading the section entitled ????. Secondly you'll need to create a view for that database. A view is like a window between you and the entire database. It "blocks out" the data you're not interested in, only allowing the data you specify to be seen or manipulated. When you create a graph, you'll be working with a view, since most of the time you'll want to display selected data from the database, rather than the whole set at once. Of course, if you want to display the whole set of data as a graph, you can do that too, simply by setting the view to be the entire database schema. For more information about views, you may want to read the section ????
How do I create a graph?
Well, first we need a database containing the data which is to be represented in the graph, and a view to go with it. Let's assume for the moment that our database contains a set of student grades, some of which we wish to view as a graph:
Sview filters only the student name, subject, and mark, from the database.
Now, you'll create the graph itself. There are several different graphs available to you with oofgraph, but for now we'll keep things simple and create a simple bar graph.
From here there are two ways to create a graph. The first way is to create a graph inside an oofGraphWindow - a special class which we've provided to allow easy integration with the Metrowerks PowerPlant environment (oofGraphWindow inherits from the LWindow class which is a core PowerPlant data type). The result is a graph inside a resizable Macintosh window - sufficient for most programming purposes. The second way of creating a graph is by making calls to the OOFGraph suite of classes directly. In the section to follow, we'll describe the first method. If you wish to maintain finer control over your graphs you'll want to create them without using oofGraphWindow: skip to the section entitled "Creating a graph directly".
Introducing oofGraphWindow
The oofGraphWindow class provides a convenient mechanism for creating graphs within your program. Each graph created is contained within its own window, and is supported by routines allowing you to copy the graph (for later pasting into a report, for example) and to print it out. Once you have a OOFILE database and a view, creating a graph involves a single line of code:
That's all there is to creating a bar graph of our data using OOFGraph. Most of the power of OOFGraph comes in the code you don't see: functions and classes that manage the auto resizing of graph, the default positioning of graph elements, the support for series data, the support for user defined preferences. OOFGraph is at the same time elegantly simple, as well as being sophisticated enough to allow you great control over the representation of your data.
And of course bar graphs aren't the only types of charts you can produce. several other types of graphs are supported too: column graphs, stacked graphs, line graphs, and others. For a full list, see the section entitled ????. If that's not enough, you can manipulate OOFGraph class methods directly to retain more control as you embed graphs in your application.
Creating a graph directly
Each graph is represented within the OOFGraph class library as an oofGraph: the different graph types (bar, column, line, etc) inherit directly from this class. Assuming we've already connected to an OOFILE database and created a view, manipulating a graph directly involves first creating an instance of the appropriate graph type:
oofGraph * BarGraphPtr = new oofBarGraph;
Next we tell the bar graph its graphical dimensions. Let's say we want a graph of size 500 by 400 pixels:
Rect GraphSizeRect;
::SetRect(&GraphSizeRect,0,0,500,400);
BarGraphPtr->setPaneRect(GraphSizeRect);
Finally we connect the view we've created to the graph, add a title and an (optional) maximum axis length, and tell the graph what draw styles to use. More on draw styles in a moment.
And once again, we have a fully functional OOFGraph chart at our disposal. So what can we do with a graph once we've created it?
Manipulating the graph image
Suppose we've created a simple bar graph within our program, but we're unhappy with the result created by OOFGraph. What we really want is a bar graph with numbers respresenting the data values placed next to the bars. Plus we want to left align the title rather than centre it. If its possible we'd also like to replace the rather standard set of colours OOFGraph has used to represent our data. The good news is that all three modifications are possible. The first two can be accomplished by accessing the bar graph's local settings. Each graph has a set of default settings (which are replacable by the user): these are the objects responsible for creating the vanilla representation you see if you make a simple call to create a graph. You can override each settings option, however, to create a custom graph:
The third modification is more complex, and requires that you've already created an array of "draw styles" (sort of like a palette of colours and patterns OOFGraph uses to draw lines and columns, etc). Assuming you've created such an array, using them in your graph is easy:
BargraphPtr->setDrawStyles(myArray);
Quite a lot of functionality in just a few short lines. There are other settable options too, of course, and also variations on modifying the draw styles. One final note: you may wish to allow the user of your prgram to toggle between a black and white representation of your graph and the colour one (to preview a graph before printing, for example). OOFGraph provides a convenient mechanism for this:
BargraphPtr->setStyleToMono();
BargraphPtr->setStyleToColor();
These calls toggle between the black and white graph representation and colour.